import axios from "axios";
export function request(config: any) {
  const instance = axios.create({
    // baseURL: "/kbs-backend",
    baseURL: import.meta.env.VITE_APP_BASE_API, //基础路径上会携带/api
    timeout: 5000,
  });

  // 默认开启Loading
  instance.interceptors.request.use(
    (config) => {
      console.log("axios-interceptors-request-config", config);
      return config;
    },
    (err) => {
      console.log("axios-interceptors-request-error", err); // for debug
      Promise.reject(err);
    }
  );
  instance.interceptors.response.use(
    (res) => {
      console.log("axios-interceptors-response-res", res);
      if (
        res.headers["content-type"] &&
        res.headers["content-type"].indexOf("octet-stream") != -1
      ) {
        return res;
      }
      return res.data;
    },
    async (err) => {
      console.log("axios-interceptors-response-error", err); // for debug
      Promise.reject(err);
    }
  );
  return instance(config);
}
